<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('智能组卷')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <form class="form-horizontal m" id="form-smart-paper">
            <input name="paperId" th:value="${examPaper.paperId}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">试卷名称：</label>
                <div class="col-sm-8">
                    <input name="name" th:value="${examPaper.name}" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">单选题：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input name="radioNum" class="form-control" type="number" min="0">
                        <span class="input-group-addon">题</span>
                        <input name="radioOneScore" class="form-control" type="number" min="0" step="0.5">
                        <span class="input-group-addon">分/题</span>
                        <input name="radioTypeScore" class="form-control" type="number" readonly>
                        <span class="input-group-addon">总分</span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">多选题：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input name="checkboxNum" class="form-control" type="number" min="0">
                        <span class="input-group-addon">题</span>
                        <input name="checkboxOneScore" class="form-control" type="number" min="0" step="0.5">
                        <span class="input-group-addon">分/题</span>
                        <input name="checkboxTypeScore" class="form-control" type="number" readonly>
                        <span class="input-group-addon">总分</span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">不定项题：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input name="indefiniteNum" class="form-control" type="number" min="0">
                        <span class="input-group-addon">题</span>
                        <input name="indefiniteOneScore" class="form-control" type="number" min="0" step="0.5">
                        <span class="input-group-addon">分/题</span>
                        <input name="indefiniteTypeScore" class="form-control" type="number" readonly>
                        <span class="input-group-addon">总分</span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">主观题：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input name="subjectiveNum" class="form-control" type="number" min="0">
                        <span class="input-group-addon">题</span>
                        <input name="subjectiveOneScore" class="form-control" type="number" min="0" step="0.5">
                        <span class="input-group-addon">分/题</span>
                        <input name="subjectiveTypeScore" class="form-control" type="number" readonly>
                        <span class="input-group-addon">总分</span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">试卷总分：</label>
                <div class="col-sm-8">
                    <input name="totalScore" class="form-control" type="number" readonly>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script type="text/javascript">
        var prefix = ctx + "jxsx/paper";

        // 计算总分
        function calculateTotalScore() {
            var radioNum = parseInt($("input[name='radioNum']").val()) || 0;
            var radioOneScore = parseFloat($("input[name='radioOneScore']").val()) || 0;
            var radioTypeScore = radioNum * radioOneScore;
            $("input[name='radioTypeScore']").val(radioTypeScore);

            var checkboxNum = parseInt($("input[name='checkboxNum']").val()) || 0;
            var checkboxOneScore = parseFloat($("input[name='checkboxOneScore']").val()) || 0;
            var checkboxTypeScore = checkboxNum * checkboxOneScore;
            $("input[name='checkboxTypeScore']").val(checkboxTypeScore);

            var indefiniteNum = parseInt($("input[name='indefiniteNum']").val()) || 0;
            var indefiniteOneScore = parseFloat($("input[name='indefiniteOneScore']").val()) || 0;
            var indefiniteTypeScore = indefiniteNum * indefiniteOneScore;
            $("input[name='indefiniteTypeScore']").val(indefiniteTypeScore);

            var subjectiveNum = parseInt($("input[name='subjectiveNum']").val()) || 0;
            var subjectiveOneScore = parseFloat($("input[name='subjectiveOneScore']").val()) || 0;
            var subjectiveTypeScore = subjectiveNum * subjectiveOneScore;
            $("input[name='subjectiveTypeScore']").val(subjectiveTypeScore);

            var totalScore = radioTypeScore + checkboxTypeScore + indefiniteTypeScore + subjectiveTypeScore;
            $("input[name='totalScore']").val(totalScore);
        }

        // 绑定输入事件
        $("input[type='number']").on('input', calculateTotalScore);

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/smartPaper", $('#form-smart-paper').serialize());
            }
        }
    </script>
</body>
</html> 